package org.opengraph.entities;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

import com.google.gson.Gson;



public abstract class Entity {
	private static String GRAPH_URL = "http://graph.facebook.com/";
	protected Gson gson = new Gson();
	
	public abstract String getId();
	
	public void sync(String accessCode){
		//this = gson.
	}
	protected static String getJson(String URL) throws Exception{
		return getJson(URL,null);
	}
	
	protected static String getJson(String URL,String accessCode) throws Exception{
		if(accessCode!= null)
			accessCode = "?access_token=" + accessCode;
		else
			accessCode = "";
		String url = GRAPH_URL+URL+accessCode;
		System.out.println("Accessing "+url);
		URL userReader = new URL(url);
		BufferedReader in = new BufferedReader(new InputStreamReader(userReader
				.openStream()));
		String str = in.readLine();
		StringBuffer sb = new StringBuffer(str);
		while(str != null){
			str = in.readLine();
			sb.append(str);
		}
		in.close();
		return sb.toString();
	}
}
